home *** CD-ROM | disk | FTP | other *** search
/ NetNews Offline 2 / NetNews Offline Volume 2.iso / news / comp / lang / c++-part1 / 3019 < prev    next >
Encoding:
Internet Message Format  |  1996-08-06  |  3.6 KB

  1. Path: keats.ugrad.cs.ubc.ca!not-for-mail
  2. From: c2a192@ugrad.cs.ubc.ca (Kazimir Kylheku)
  3. Newsgroups: comp.lang.ada,comp.lang.c++,comp.lang.c,comp.lang.modula3,comp.lang.modula2,comp.lang.eiffel
  4. Subject: Re: Hungarian notation
  5. Date: 21 Jan 1996 10:02:24 -0800
  6. Organization: Computer Science, University of B.C., Vancouver, B.C., Canada
  7. Message-ID: <4dtv3gINNo9u@keats.ugrad.cs.ubc.ca>
  8. References: <30C40F77.53B5@swsbbs.com> <4cvu68$2jb@macaw.cyberport.com> <4d21og$iab@news.xmission.com> <4d2ok0$69s@beach.and.nl>
  9. NNTP-Posting-Host: keats.ugrad.cs.ubc.ca
  10.  
  11. In article <4d2ok0$69s@beach.and.nl>, Jos A. Horsmeier <jos@and.nl> wrote:
  12. >Prefixing 'psz' to every zero terminated string is plain silly if we're
  13. >talking about, say, employee names or beer brand names; something like 
  14. >'empnm' and 'beernm' should have been used instead. Only then, statements
  15. >like:
  16. >
  17. >    if (!strcmp(empnmBoss, beernmMyFavBeer))
  18. >
  19. >trigger the reader that something fishy is going on here ... HN, as it
  20. >is used now, doesn't add any clarity to the code at all, i.e. the statement:
  21. >
  22. >    if (!strcmp(pszBoss, pszMyFavBeer))
  23. >
  24. >just tells me that I want to compare my favorite beer and a boss's name,
  25. >which is silly too, but it's not the 'psz' prefix that rings a bell here;
  26. >it's just the 'Boss' and 'MyFavBeer' name parts that catch the eye.
  27.  
  28. I agree. The "psz" is just a redundant prefix that pollutes the symbol table.
  29. If anyone wrote code with random consonants thrown in front of every perfectly
  30. good name, I'd fire them on the spot, and tell them to go rearrange their
  31. closet.
  32.  
  33. >Just adding domain name prefixes to the names of objects doesn't help
  34. >anyone; notion of domains should be present in the language itself if
  35. >one really wants domains, instead of just comparable types as implemented
  36. >in the C language. Any (decent) C compiler feels perfectly fine if one
  37. >feeds it something like:
  38. >
  39. >    #include <stdio.h>
  40. >    #include <string.h>
  41. >
  42. >    typedef char* empnm_t;
  43. >    typedef char* beernm_t;
  44.  
  45. Even that is going overboard. Someone will later see "empnm_t", and wonder what
  46. the heck it is. If you mean "char *", just say "char *". The typedef operator
  47. has its uses, but redefining simple types, like char * or int is not one of
  48. them. The chief advantage is that you can use it with structs so that you can
  49. eliminate having to write the struct keyword later on.
  50.  
  51. I just wrote a 12000 line project that doesn't have one typedef in it (save for
  52. automatically generated XDR definitions). The code is easy to read; I can go
  53. back to it and understand precisely what is going on without hunting for nested
  54. definitions.
  55.  
  56. I gave the code to another programmer who is doing a Windows interface, and he
  57. said that everything was nicely laid out for him, enabling him to incoroporate
  58. the bits in a short time.
  59.  
  60. Typedef-like constructs are useful in poorly thought-out languages like Modula
  61. or Pascal, whose compilers can typically perform typechecks based only on name
  62. equivalence. That is to say, if I declare two types that are both integers, the
  63. compiler will say that the two types are not equivalent, because it goes only
  64. as far as to check the name. This is a cop out which simplifies doing one of
  65. the more difficult phases of compiler construction, which is type checking. It
  66. has nothing to do with implementing "domains", and everything to do with lazy
  67. compiler construction. Real compilers will detect structure equivalence between
  68. types so that you don't have to obfuscate your code with confusing type names.
  69. To implement domains, just lobotomize the compiler by removing the structure
  70. equivalence checking so that size_t and time_t become incompatible types.
  71. -- 
  72.  
  73.